package cn.bin758.h5game.module.game.dal.mysql.record;

import java.util.*;

import cn.bin758.h5game.framework.common.pojo.PageResult;
import cn.bin758.h5game.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.bin758.h5game.framework.mybatis.core.mapper.BaseMapperX;
import cn.bin758.h5game.module.game.dal.dataobject.record.RecordDO;
import org.apache.ibatis.annotations.Mapper;
import cn.bin758.h5game.module.game.controller.admin.record.vo.*;

/**
 * 对局信息 Mapper
 *
 * @author bin758
 */
@Mapper
public interface RecordMapper extends BaseMapperX<RecordDO> {

    default PageResult<RecordDO> selectPage(RecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RecordDO>()
                .likeIfPresent(RecordDO::getName1, reqVO.getName1())
                .likeIfPresent(RecordDO::getName2, reqVO.getName2())
                .betweenIfPresent(RecordDO::getStart, reqVO.getBeginStart(), reqVO.getEndStart())
                .betweenIfPresent(RecordDO::getEnd, reqVO.getBeginEnd(), reqVO.getEndEnd())
                .eqIfPresent(RecordDO::getWin, reqVO.getWin())
                .betweenIfPresent(RecordDO::getSteps, reqVO.getBeginSteps(), reqVO.getEndSteps())
                .eqIfPresent(RecordDO::getType, reqVO.getType())
                .orderByDesc(RecordDO::getId));
    }

    default PageResult<RecordDO> selectPage2(RecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RecordDO>()
                .eq(RecordDO::getPlayer1,reqVO.getId()).or().eq(RecordDO::getPlayer2,reqVO.getId())
                .orderByDesc(RecordDO::getId));
    }

    default List<RecordDO> selectList(RecordExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<RecordDO>()
                .likeIfPresent(RecordDO::getName1, reqVO.getName1())
                .likeIfPresent(RecordDO::getName2, reqVO.getName2())
                .betweenIfPresent(RecordDO::getStart, reqVO.getBeginStart(), reqVO.getEndStart())
                .betweenIfPresent(RecordDO::getEnd, reqVO.getBeginEnd(), reqVO.getEndEnd())
                .eqIfPresent(RecordDO::getWin, reqVO.getWin())
                .betweenIfPresent(RecordDO::getSteps, reqVO.getBeginSteps(), reqVO.getEndSteps())
                .eqIfPresent(RecordDO::getType, reqVO.getType())
                .orderByDesc(RecordDO::getId));
    }

}
